class MyPageHeader extends BaseEditMaster {
    constructor(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
            returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl) {
        super(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
                returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl);
    }
    // 得到数据
    GetEntityData() {
        var item = {};
        item['addressId'] = $("#AddressId").val();
        item['addressNo'] = formatNullInputValue($.trim($("#AddressNo").val()));
        item['deliveryAddress'] = formatNullInputValue($.trim($("#DeliveryAddress").val()));
        item['createdBy'] = $.trim($("#UserId").val());
        item['updatedBy'] = $.trim($("#UserId").val());

        return JSON.stringify(item);
    }
    FillData(data) {
        $("#AddressId").val(data.addressId);
        $("#AddressNo").val(data.addressNo);
        $("#DeliveryAddress").val(data.deliveryAddress);

        // 最后的审核人、审核日期
        //$("#CheckedBy").val(item.checkedBy);
        //$("#CheckedByName").val(item.checkedByName);
        //$("#CheckedDate").val(item.checkedDate === null ? '' : item.checkedDate);
        //$("#CheckedStatus").val(item.checkedStatus);
        //$('#FlowOrderNo').val(item.flowOrderNo);
        this.currentTaskPrivileges = data.currentTaskPrivileges;
        this.nextTaskPrivileges = data.nextTaskPrivileges;
        this.unCheckFlag = data.unCheckFlag;

        this.SetPageElementStatus();
        $("#CustomerNo").focus();
    }
    SetPageElementStatus() {
        super.SetPageElementStatus(function () {
            //$("#ButSave").hide();
        }, function () {
            //$("#ButSave").show();
        }, function () {

        });
    }
    Save(flag) {
        super.Save(function (data, $self) {
            if (data > 0) {
                if (parseInt($self.pageStatus) === 1) {
                    $("#AddressId").val(data);   // 设置刚才插入的记录ID
                    $self.dataId = data;
                    $self.pageStatus = 2;
                }
                if (flag === 0) {
                    $self.New();
                }
            }
        });
    }
    OnNew() {
        // 默认设置一些值
        $('#AddressId').val("0");
        super.OnNew();
        $("#AddressNo").focus();
    }
}

var _InstancePageHeader = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let _pageStatus = $("#Action").val();
    let _dataId = $("#AddressId").val();

    let delivery_address_list_result = $.cookie("delivery_address_list_result") === undefined ? "" : $.cookie("delivery_address_list_result");
    let _pageListData = [];
    if (delivery_address_list_result !== "") {
        _pageListData = delivery_address_list_result.split(',');
        $("#rec_total_rows").text(_pageListData.length);
        $("#rec_cur_row").text($.inArray(_dataId, _pageListData) + 1);

        if (_pageListData.length > 0) {
            let index = $.inArray(_dataId, _pageListData);
            if (index === 0) {
                $("#ButPrev").attr("disabled", "disabled");
            } else {
                $("#ButNext").removeAttr("disabled");
            }
            if (index === (_pageListData.length - 1)) {
                $("#ButNext").attr("disabled", "disabled");
            } else {
                $("#ButPrev").removeAttr("disabled");
            }
        }
    } else {
        $("#rec_total_rows").text("1");
        $("#rec_cur_row").text("1");
    }

    _InstancePageHeader = new MyPageHeader(_dataId, 0, 0, _pageStatus, _pageListData,
            "/master/delivery_address/list.html",
            "/master/delivery_address/fetchByKey.html",
            "/master/delivery_address/save.html",
            "/master/delivery_address/export.html",
            "/master/delivery_address/print.html");

    _InstancePageHeader.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    var w = $(window).width();
    var h = $(window).height();

    $(".data__table_wrapper").css({width: w - 40, height: h - 120});
}

//-----------------------------------------------------------------------------
// 验证函数
//-----------------------------------------------------------------------------
$.validator.setDefaults({
    ignore: 'hidden, [reaonly=readonly]'
});
$.validator.addMethod("valueNotEquals", function (value, element, arg) {
    return arg !== value;
}, "Value must not equal arg.");

$(function () {
    $("#form_data").validate({
        // Step 1：设置验证规则和错误消息
        rules: {
            _AddressNo: "required"

        },
        messages: {
            _AddressNo: "请填写地址编号。"

        },
        // Step 2：设置验证触发事件
        onclick: false,
        onfocusout: false,
        onfocusin: false,
        onkeyup: false,
        onkeydown: false,
        focusInvalid: false,
        // Step 3：设置错误信息提示
        showErrors: window.showErrors  //使用自定义的错误显示方法
    });
});